#include "lattice3.h"

class LatticeTmunuCorrelators: public MyLattice
{
      public:
      float TmunuSum(int t, int dir1, int dir2)
      {
           float Ti = 0; 
           float Task = 0;
           
           int x, y, z;
           coordinate *crd;
           
           for(x = 0; x < NX; x++)
           for(y = 0; y < NX; y++)
           for(z = 0; z < NX; z++)
           {
                 crd = new coordinate(x,y,z,t);
                 float temp = Tmunu(*crd, dir1, dir2);
                 Ti += temp;
                 delete crd;
           }
           return Ti;
      };

      float TmunuSum(int dir1, int dir2)
      {
           float Ti = 0; 
           float Task = 0;
           
           int x, y, z, t;
           coordinate *crd;
           
           for(x = 0; x < NX; x++)
           for(y = 0; y < NX; y++)
           for(z = 0; z < NX; z++)
           for(t = 0; t < NT; t++)
           {
                 crd = new coordinate(x,y,z,t);
                 float temp = Tmunu(*crd, dir1, dir2);
                 Ti += temp;
                 delete crd;
           }
           return Ti/NX/NX/NX/NT;
      };

      
      float TmunuCorrelator(int dt, int dir1, int dir2)
      {
           float Tc = 0;
           
           int t;
           for(t = 0; t < NT; t++)
           {
                Tc += TmunuSum(t, dir1, dir2)*TmunuSum(t + dt, dir1, dir2);
           }
           
           return Tc/NX/NX/NX/NT;
      };
      
      float TmunuCorrelator(int dt)
      {
           float Tc = (TmunuCorrelator(dt, 2,3) + TmunuCorrelator(dt, 3,4) + TmunuCorrelator(dt, 4,2))/3.0;
           return Tc;
      };

      
      LatticeTmunuCorrelators Sweep()
      {
           LatticeTmunuCorrelators SweepedLattice;
           
           int x,y,z,t;
           
           for(x = 1; x <= NX; x++)
           for(y = 1; y <= NX; y++)
           for(z = 1; z <= NX; z++)
           for(t = 1; t <= NT; t++)
           {
                coordinate crdOld(x,y,z,t);
                coordinate crdNew(x,y,z,NT - t + 1);
                SweepedLattice.WriteLink(GetLink(crdOld, 2), crdNew, 2);
                SweepedLattice.WriteLink(GetLink(crdOld, 3), crdNew, 3);
                SweepedLattice.WriteLink(GetLink(crdOld, 4), crdNew, 4);
                SweepedLattice.WriteLink(GetLink(crdOld.back(1), 1).inv(), crdNew, 1 );
           }
           SweepedLattice.StorePlaquettes();
           
           return SweepedLattice;
      }
      
};
